package com.jaychen.spring.core.io.loader;

import com.jaychen.spring.core.io.ClassPathXmlResource;
import com.jaychen.spring.core.io.Resource;

import java.io.FileNotFoundException;
import java.net.URL;

/**
 * 资源定位
 *
 * @Author Jay Chen
 * @Date 2020/11/9 18:58
 */
public class ResourceLoader {

    /**
     * 加载resource
     *
     * @param path 文件路径
     * @return FileResource
     */
    public Resource getResource(String path) throws FileNotFoundException {
        // 资源定位
        URL url = path.getClass().getResource(path);
        if (url.getPath().startsWith("/")) {
            return new ClassPathXmlResource(url);
        }
        throw new FileNotFoundException("Please check your file");
    }

}
